/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package yancy.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import yancy.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * Controller公共组件
 *
 * @author Mark sunlightcs@gmail.com
 */
public abstract class AbstractController {
    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected SysUserEntity getUser() {
        return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
    }

    protected Long getUserId() {
        return getUser().getUserId();
    }

    protected Page getPage(Map<String, Object> params) {
        Long page = 1L, limit = 10L;
        Object p;
        if ((p = params.get("page")) != null) {
            page = Long.parseLong(p.toString());
        }
        if ((p = params.get("limit")) != null) {
            limit = Long.parseLong(p.toString());
        }
        return new Page(page, limit);
    }
}
